package com.dkm.orproject.dkmoa.service.serviceimpl;

import com.dkm.orproject.dkmoa.dao.OaCarUpkeepMapper;
import com.dkm.orproject.dkmoa.domain.OaCarUpkeep;
import com.dkm.orproject.dkmoa.domain.OaPersonnel;
import com.dkm.orproject.dkmoa.service.OaCarUpkeepService;
import com.dkm.orproject.utils.utils.IdToobtainUtils;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ClassName : OaCarUpkeepServiceImpl  //类名
 * @Description : 车辆保养服务接口实现类  //描述
 * @Author : 易嵘  //作者
 * @Date: 2021-02-25 14:27  //时间
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class OaCarUpkeepServiceImpl implements OaCarUpkeepService {

    /**
     * 车辆保养Mapper
     */
    @Resource
    private OaCarUpkeepMapper carUpkeepMapper;

    /**
     * id生成工具类
     */
    @Resource
    private IdToobtainUtils idToobtainUtils;

    /**
     * id查询
     * @param id 车辆保养id
     * @return
     */
    @Override
    public OaCarUpkeep findById(Long id) {
        return carUpkeepMapper.selectByPrimaryKey(id);
    }

    /**
     * 新增
     * @param personnel 操作人
     * @param upkeep 车辆保养信息
     * @return
     */
    @Override
    public int add(OaPersonnel personnel, OaCarUpkeep upkeep) {
        upkeep.setPkCarUpkeepId(idToobtainUtils.getNumberId());
        upkeep.setIsRevision("1");
        upkeep.setCreatedBy(personnel.getPersonnelName());
        return carUpkeepMapper.insertSelective(upkeep);
    }

    /**
     * 修改
     * @param personnel 操作人
     * @param upkeep 车辆保养信息
     * @return
     */
    @Override
    public int update(OaPersonnel personnel, OaCarUpkeep upkeep) {
        upkeep.setUpdatedTime(new Date());
        upkeep.setUpdatedBy(personnel.getPersonnelName());
        return carUpkeepMapper.updateByPrimaryKeySelective(upkeep);
    }

    /**
     * id删除
     * @param id 车辆保养id
     * @return
     */
    @Override
    public int delete(Long id) {
        return carUpkeepMapper.deleteByPrimaryKey(id);
    }

    /**
     * id查询集合
     * @param list 车辆保养id集合
     * @return 车辆保养信息集合
     */
    @Override
    public List<OaCarUpkeep> selectAll(List<Long> list) {
        return carUpkeepMapper.selectAll(list);
    }

    /**
     *  批量删除
     * @param list 车辆信息保养id集合
     * @return
     */
    @Override
    public int deleteAll(List<Long> list) {
        return carUpkeepMapper.deleteAll(list);
    }

    /**
     *
     * @param carUpkeepName 车辆保养名称
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param page 当前页数
     * @param limit 显示行数
     * @return
     */
    @Override
    public List<OaCarUpkeep> findAll(String carUpkeepName, String startTime, String endTime, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        return carUpkeepMapper.findAll(carUpkeepName,startTime,endTime);
    }

    /**
     *
     * @param carUpkeepName 车辆保养名称
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    @Override
    public Long rowCount(String carUpkeepName, String startTime, String endTime) {
        return carUpkeepMapper.rowCount(carUpkeepName,startTime,endTime);
    }
}
